From b4aac42605394535a5fa8a3567336a1adc1e3f1a Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 5 Jun 2019 19:36:35 +0000 Subject: [PATCH] widget-factory: Add another popover menu example This one is taken from https://gitlab.gnome.org/GNOME/gtk/issues/1824 --- demos/widget-factory/widget-factory.c | 53 ++++++- demos/widget-factory/widget-factory.ui | 195 ++++++++++++++++++++++++- 2 files changed, 245 insertions(+), 3 deletions(-) diff --git a/demos/widget-factory/widget-factory.c b/demos/widget-factory/widget-factory.c index af4a03f733..2ccc659c1b 100644 --- a/demos/widget-factory/widget-factory.c +++ b/demos/widget-factory/widget-factory.c @@ -118,6 +118,8 @@ activate_delete (GSimpleAction *action, GtkWidget *window = user_data; GtkWidget *infobar; + g_print ("Activate action delete\n"); + if (!on_page (2)) return; @@ -1634,6 +1636,7 @@ activate (GApplication *app) } accels[] = { { "app.about", { "F1", NULL } }, { "app.quit", { "q", NULL } }, + { "app.open-in", { "n", NULL } }, { "win.dark", { "d", NULL } }, { "win.search", { "s", NULL } }, { "win.delete", { "Delete", NULL } }, @@ -1921,6 +1924,41 @@ local_options (GApplication *app, return -1; } +static void +activate_action (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) +{ + g_print ("Activate action %s\n", g_action_get_name (G_ACTION (action))); +} + +static void +select_action (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) +{ + g_print ("Set action %s to %s\n", + g_action_get_name (G_ACTION (action)), + g_variant_get_string (parameter, NULL)); + + g_simple_action_set_state (action, parameter); +} + +static void +toggle_action (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) +{ + GVariant *state = g_action_get_state (G_ACTION (action)); + + g_print ("Toggle action %s to %s\n", + g_action_get_name (G_ACTION (action)), + g_variant_get_boolean (state) ? "false" : "true"); + + g_simple_action_set_state (action, + g_variant_new_boolean (!g_variant_get_boolean (state))); +} + int main (int argc, char *argv[]) { @@ -1935,7 +1973,20 @@ main (int argc, char *argv[]) { "beer", NULL, NULL, "false", NULL }, { "water", NULL, NULL, "true", NULL }, { "dessert", NULL, "s", "'bars'", NULL }, - { "pay", NULL, "s", NULL, NULL } + { "pay", NULL, "s", NULL, NULL }, + { "print", activate_action, NULL, NULL, NULL }, + { "share", activate_action, NULL, NULL, NULL }, + { "labels", activate_action, NULL, NULL, NULL }, + { "open-in", activate_action, NULL, NULL, NULL }, + { "cut", activate_action, NULL, NULL, NULL }, + { "copy", activate_action, NULL, NULL, NULL }, + { "paste", activate_action, NULL, NULL, NULL }, + { "pin", toggle_action, NULL, "true", NULL }, + { "size", select_action, "s", "'medium'", NULL }, + { "berk", toggle_action, NULL, "true", NULL }, + { "broni", toggle_action, NULL, "true", NULL }, + { "drutt", toggle_action, NULL, "true", NULL }, + { "upstairs", toggle_action, NULL, "true", NULL }, }; gint status; diff --git a/demos/widget-factory/widget-factory.ui b/demos/widget-factory/widget-factory.ui index 7cdc6981ae..5ac9074d75 100644 --- a/demos/widget-factory/widget-factory.ui +++ b/demos/widget-factory/widget-factory.ui @@ -2433,11 +2433,12 @@ microphone-sensitivity-medium-symbolic 10 - start + fill 6 - start + fill + 1 6 @@ -2509,6 +2510,12 @@ microphone-sensitivity-medium-symbolic + + + view-more-symbolic + new_style_menu + + @@ -3509,4 +3516,188 @@ bad things might happen. + + + + main + vertical + + + fill + + + printer-symbolic + 1 + app.print + 1 + center + + + + + + emblem-shared-symbolic + 1 + app.share + 1 + center + + + + + + + + + + + Open in New Window + app.open-in + + + + + + + + + + Edit + 0 + 1 + + + + + edit-cut-symbolic + 1 + none + + + + + edit-copy-symbolic + 1 + none + + + + + edit-paste-symbolic + 1 + none + + + + + + + + + + Pin + app.pin + + + + + Select Labels… + app.labels + + + + + Share… + app.share + + + + + + + + Basement + basement + + + + + + + + Large + app.size + 'large' + + + + + Medium + app.size + 'medium' + + + + + Small + app.size + 'small' + + + + + + + + Move to Trash + win.delete + + + + + + + basement + vertical + + + Basement + title + main + + + + + + + + Berk + app.berk + + + + + Broni + app.broni + + + + + Drutt + app.drutt + + + + + The Thing Upstairs + app.upstairs + + + + + -- 2.30.2